package com.ninetaildemonfox.zdl.socialproject.mvp.ui.fragment;


import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.kongzue.dialog.v3.WaitDialog;
import com.ninetaildemonfox.zdl.ninetaildemonfox.base.BaseFragment;
import com.ninetaildemonfox.zdl.socialproject.R;
import com.ninetaildemonfox.zdl.socialproject.mvp.contract.SystemNotificationContract;
import com.ninetaildemonfox.zdl.socialproject.mvp.presenter.SystemNotificationPresenter;
import com.ninetaildemonfox.zdl.socialproject.mvp.ui.activity.SystemNewsActivity;

import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @author NineTailDemonFox
 * @date 2019/7/23 13:21
 * 功能描述：系统通知
 * 联系方式：1037438704@qq.com
 */
public class SystemNotificationFragment extends BaseFragment implements SystemNotificationContract {
    @BindView(R.id.ll_system_news)
    LinearLayout llSystemNews;
    @BindView(R.id.ll_radio_broadcast)
    LinearLayout llRadioBroadcast;
    @BindView(R.id.ll_evaluate)
    LinearLayout llEvaluate;
    @BindView(R.id.ll_payment_reminder)
    LinearLayout llPaymentReminder;
    @BindView(R.id.text_1)
    TextView text_1;
    @BindView(R.id.text_2)
    TextView text_2;
    @BindView(R.id.text_3)
    TextView text_3;
    @BindView(R.id.text_4)
    TextView text_4;
    @BindView(R.id.text_context_1)
    TextView text_context_1;
    @BindView(R.id.text_context_2)
    TextView text_context_2;
    @BindView(R.id.text_context_3)
    TextView text_context_3;
    @BindView(R.id.text_context_4)
    TextView text_context_4;
    @BindView(R.id.text_time_1)
    TextView text_time_1;
    @BindView(R.id.text_time_2)
    TextView text_time_2;
    @BindView(R.id.text_time_3)
    TextView text_time_3;
    @BindView(R.id.text_time_4)
    TextView text_time_4;
    private SystemNotificationPresenter presenter;

    @Override
    protected int getLayoutResource() {
        return R.layout.fragment_system_notification;
    }

    @Override
    protected void onInitView(Bundle savedInstanceState) {
        presenter = new SystemNotificationPresenter(this, fgtContext);
    }

    @Override
    public void onResume() {
        super.onResume();
        presenter.getSystemNotice(token);
    }

    @OnClick({R.id.ll_system_news, R.id.ll_radio_broadcast, R.id.ll_evaluate, R.id.ll_payment_reminder})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ll_system_news:
                //系统消息
                SystemNewsActivity.start(getContext(), 1);
                break;
            case R.id.ll_radio_broadcast:
                //广播消息
                SystemNewsActivity.start(getContext(), 2);
                break;
            case R.id.ll_evaluate:
                //评价
                SystemNewsActivity.start(getContext(), 3);
                break;
            case R.id.ll_payment_reminder:
                //缴费提醒
                SystemNewsActivity.start(getContext(), 4);
                break;
            default:
        }
    }

    public static SystemNotificationFragment newInstance() {
        SystemNotificationFragment dHomeFragment = new SystemNotificationFragment();
        Bundle bundle = new Bundle();
        dHomeFragment.setArguments(bundle);
        return dHomeFragment;
    }


    @Override
    public void Success(List<Map<String, String>> data) {
        for (int i = 0; i < data.size(); i++) {
            switch (i) {
                case 0:
                    if (data.get(i).get("count").equals("0") || data.get(i).get("count") == null) {
                        text_1.setVisibility(View.GONE);
                    } else {
                        text_1.setVisibility(View.VISIBLE);
                    }
                    text_1.setText(data.get(i).get("count"));
                    text_time_1.setText(data.get(i).get("create_time"));
                    text_context_1.setText(data.get(i).get("content"));
                    break;
                case 1:
                    if (data.get(i).get("count").equals("0") || data.get(i).get("count") == null) {
                        text_2.setVisibility(View.GONE);
                    } else {
                        text_2.setVisibility(View.VISIBLE);
                    }
                    text_2.setText(data.get(i).get("count"));
                    text_time_2.setText(data.get(i).get("create_time"));
                    text_context_2.setText(data.get(i).get("content"));
                    break;
                case 2:
                    if (data.get(i).get("count").equals("0") || data.get(i).get("count") == null) {
                        text_3.setVisibility(View.GONE);
                    } else {
                        text_3.setVisibility(View.VISIBLE);
                    }
                    text_3.setText(data.get(i).get("count"));
                    text_time_3.setText(data.get(i).get("create_time"));
                    text_context_3.setText(data.get(i).get("content"));
                    break;
                case 3:
                    if (data.get(i).get("count").equals("0") || data.get(i).get("count") == null) {
                        text_4.setVisibility(View.GONE);
                    } else {
                        text_4.setVisibility(View.VISIBLE);
                    }
                    text_4.setText(data.get(i).get("count"));
                    text_time_4.setText(data.get(i).get("create_time"));
                    text_context_4.setText(data.get(i).get("content"));
                    break;
                default:
            }
        }
    }

    @Override
    public void Failed(String msg) {

    }

    @Override
    public void showLoading() {
        WaitDialog.show(fgtContext, "数据加载中");
    }
}
